package com.cheer.controller;

import com.cheer.common.Result;
import com.cheer.service.AuthService;
import com.cheer.service.OaUserService;
import com.cheer.vo.OaRankItemVO;
import com.cheer.vo.OaRankVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/rank")
@Api(tags = "排名controller")
public class OaRankController {

    @Autowired
    private OaUserService oaUserService;

    @Autowired
    private AuthService authService;

    @ApiOperation("查询排行榜")
    @GetMapping("/info")
    public Result<OaRankVO> info(@RequestParam String type, HttpSession session) {
        OaRankVO rankVO = oaUserService.rankInfo(type, authService.getUserId(session));
        return Result.success(rankVO);
    }

    @ApiOperation("查询排行榜")
    @GetMapping("/range")
    public Result<List<OaRankItemVO>> range(@RequestParam Integer pageNum,
                                            @RequestParam Integer pageSize,
                                            @RequestParam String type,
                                            HttpSession session) {
        authService.getUserId(session);
        List<OaRankItemVO> rankItemVOS = oaUserService.rankRange(pageNum, pageSize, type);
        return Result.success(rankItemVOS);
    }

}
